import { AbstractBaseService } from "./base.service";
import CategoryModel from "../model/category.model";
import { CategoryVm } from "../vm/category.vm";

export class CategoryService extends AbstractBaseService<CategoryModel, CategoryVm> {
    fromVmToModel(vm: CategoryVm): CategoryModel {
        const model = new CategoryModel();
        let keys = Object.getOwnPropertyNames(model);
        for (let key in vm) {
            if (keys.indexOf(key) >= 0) {
                (model as any)[key] = (vm as any)[key];
            }
        }
        return model;
    }

    fromModelToVm(model: CategoryModel): CategoryVm {
        const vm = new CategoryVm();
        let keys = Object.getOwnPropertyNames(vm);
        for (let key in model) {
            if (keys.indexOf(key) >= 0) {
                (vm as any)[key] = (model as any)[key];
            }
        }
        return vm;
    }
}

export const categoryService = new CategoryService('admin/category');
export default categoryService;